package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;

import com.company.project.common.utils.DataResult;

import com.company.project.entity.SysManageEntity;
import com.company.project.service.SysManageService;



/**
 * 控制报名启用和停止
 *
 * @author ls
 * @email *****@mail.com
 * @date 2021-04-09 11:08:07
 */
@Controller
@RequestMapping("/")
public class SysManageController {
    @Autowired
    private SysManageService sysManageService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/sysManage")
    public String sysManage() {
        return "sysmanage/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("sysManage/add")
    @RequiresPermissions("sysManage:add")
    @ResponseBody
    public DataResult add(@RequestBody SysManageEntity sysManage){
        sysManageService.save(sysManage);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("sysManage/delete")
    @RequiresPermissions("sysManage:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        sysManageService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("sysManage/update")
    @RequiresPermissions("sysManage:update")
    @ResponseBody
    public DataResult update(@RequestBody SysManageEntity sysManage){
        sysManageService.updateById(sysManage);
        return DataResult.success();
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "查询分页数据")
    @PostMapping("sysManage/listByPage")
    @RequiresPermissions("sysManage:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SysManageEntity sysManage){
        Page page = new Page(sysManage.getPage(), sysManage.getLimit());
        LambdaQueryWrapper<SysManageEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(SysManageEntity::getId, sysManage.getId());
        IPage<SysManageEntity> iPage = sysManageService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
